package com.lzp.service.impl;

import com.lzp.mapper.CarouselMapper;
import com.lzp.pojo.Carousel;
import com.lzp.service.CarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 轮播图业务实现接口
 *
 * @author dtyy
 * @date 2020/8/2
 */
@Service
public class CarouselServiceImpl implements CarouselService {

    @Autowired
    private CarouselMapper carouselMapper;

    /**
     * 查找所有可展示轮播图，并排序
     *
     * @param isShow 是否展示，条件可省略
     * @return
     */
    @Override
    public List<Carousel> listCarousels(int isShow) {

        Example example = new Example(Carousel.class);
        // 根据属性进行排序()
        example.orderBy("sort").desc();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("isShow", isShow);

        // 按条件查询
        List<Carousel> result = carouselMapper.selectByExample(example);

        return result;
    }

}
